package com.woniuxy.hospital.shiro;

import com.woniuxy.hospital.service.IHplPermService;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedHashMap;
import java.util.Map;

public class PowerMapFactoryBean implements FactoryBean<Map<String,String>> {
    @Autowired
    private IHplPermService permService;
    @Override
    public Map<String,String> getObject() throws Exception {
        Map<String,String> maps = new LinkedHashMap<>();
        maps.put("/k15/admin/login","anon");//放行
        maps.put("/hpl-admin/login","anon");//放行
        maps.put("/power/meuns","jwt");//查询菜单

        maps.put("/css/**", "anon");
        maps.put("/js/**","anon");
        maps.put("/images/**","anon");
        maps.put("/logout", "logout");//退出登录清空数据


        //查询所有的权限
        permService.list().forEach(p->{
            //访问链接link对应权限标识sign
            maps.put("/"+p.getLink(), "authc,myperms["+p.getSign()+"]");//权限
            if (p.getLink().startsWith("role") || p.getLink().startsWith("perm") || p.getLink().startsWith("admin")) {
                maps.put("/"+p.getLink(), "jwt,myperms["+p.getSign()+"]");//权限
            }

        });
        //maps.put("/**","authc");//认证

        return maps;
    }

    @Override
    public Class<?> getObjectType() {
        return Map.class;
    }
}
